package com.ydx.meituan.config.log;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.FilterConfig;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


/**
 * Description:打印请求日志的过滤器
 */
public class LogFilter implements Filter {

    private static final Logger logger = LoggerFactory.getLogger(LogFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
        logger.info("LogFilter.RemoteHost==>accept params from: " + request.getRemoteHost()+" url: "+((HttpServletRequest) request).getRequestURL());
            try {
                chain.doFilter(request, response);
            } catch (IOException e) {
              logger.error(e.getMessage(),e);
            } catch (ServletException e) {
                logger.error(e.getMessage(),e);
            }
    }
}
